/**
 * @Author liangzai
 * @Description:
 */
class Person implements Cloneable{
    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
public class Test {

    public static void test1() {
        int[] array = {1,2,3,4};
        System.out.println(array[10]);
    }

    public static void main12(String[] args) {
        try {
            test1();
            System.out.println("结束try的代码.....");
        }catch (ArrayIndexOutOfBoundsException e) {

        }
        System.out.println("fsfadsafsa");
    }

    public static int  testFinally() {
        try {
            return 10;
        } catch (InputMismatchException e) {
            e.printStackTrace();
        } finally {
            System.out.println("finally中代码");
            return 20;
        }
    }

    public static void main11(String[] args) {
        System.out.println(testFinally());
    }

    public static int getData(){
        try (Scanner sc = new Scanner(System.in)) {
            int data = sc.nextInt();
            return data;
        } catch (InputMismatchException e) {
            e.printStackTrace();
        } finally {
            System.out.println("finally中代码");
        }
        System.out.println("try-catch-finally之后代码");
        /*if(null != sc){
            sc.close();
        }*/
        return 0;
    }
    public static void main10(String[] args) {
        //finally一般用于资源的释放
        int data = getData();
        System.out.println(data);
    }
    public static void main9(String[] args) {
        int[] array = {1,2,3};
        try {
            //System.out.println(array[21]);
            //array = null;
            System.out.println(array.length);
        }catch (NullPointerException e) {
            System.out.println("处理NullPointerException异常...");
            e.printStackTrace();
        }catch (Exception e) {
            System.out.println("处理Exception异常...");
            e.printStackTrace();
        }finally {
            System.out.println("finally被执行了.....[不管是否发生异常 finally都会被执行]");
        }
        System.out.println("after");
    }

    public static void main8(String[] args) {
        int[] array = {1,2,3};
        try {
            System.out.println(array[21]);
            array = null;
            System.out.println(array.length);
        }catch (ArrayIndexOutOfBoundsException | NullPointerException  e) {
            System.out.println("处理ArrayIndexOutOfBoundsException | NullPointerException 异常...");
            e.printStackTrace();
        }
        System.out.println("after");
    }


    public static void main7(String[] args) {
        int[] array = {1,2,3};
        try {
            System.out.println(array[21]);
            array = null;
            System.out.println(array.length);
        }catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("处理ArrayIndexOutOfBoundsException异常...");
            e.printStackTrace();
        }catch (NullPointerException e) {
            System.out.println("处理NullPointerException异常...");
            e.printStackTrace();
        }
        System.out.println("after");
    }

    public static void funcction(int a) throws CloneNotSupportedException {
        if(a == 10) {
            throw new CloneNotSupportedException();
        }
    }

    public static void main6(String[] args) {
        try {
            funcction(10);
            System.out.println("哈哈哈.....");
        }catch (CloneNotSupportedException e) {
            System.out.println("捕获了异常,处理异常....");
        }
        System.out.println("程序正常继续执行....");
    }

    public static void testException(int a) {
        if(a == 0) {
            throw new ArithmeticException("a == 0");
            //System.out.println("fafafdsa");
        }
    }

    public static void main5(String[] args) {
        testException(0);
    }



    public static void main4(String[] args)  throws CloneNotSupportedException,NullPointerException{
        /*funcction();*/
        Person person = new Person();
        Person person1 = (Person) person.clone();
    }

    public static void main3(String[] args) {
        //System.out.println(10/0);
        /*int[] array = {1,2,3,4,5};
        System.out.println(array[10]);*/
        int[] array = null;
        System.out.println(array.length);
        System.out.println("after");
    }

    public static int countSegments(String s) {
        int len = s.length();
        if(len == 0) {
            return 0;
        }
        int count = 0;
        String[] ss = s.split(" ");
        for(String r : ss) {
            if(r.length() != 0) {
                count++;
            }
        }
        return count;
    }


    public static void main2(String[] args) {
        int count = countSegments(", , , ,        a, eaefa");
        System.out.println(count);
    }

    //"He2llo"
    public String toLowerCase(String s) {
        //String ret = "";
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            //判断当前字符 是不是字母
            if(Character.isLetter(ch)) {
                //判断是不是大写字母
                if(Character.isUpperCase(ch)) {
                    ch = (char)(ch + 32);
                }
            }
            stringBuilder.append(ch);
        }
        return stringBuilder.toString();
    }




    String str = new String("good");
    char[ ] ch = { 'a' , 'b' , 'c' };
    public static void main1(String args[]){
        Test ex = new Test();
        ex.change(ex.str,ex.ch);
        System.out.print(ex.str + " and ");
        System.out.print(ex.ch);
    }
    public void change(String str,char ch[ ]){
        str = "test ok";
        ch[0] = 'g';
    }

    public static void fun1(int[] array) {
        array = new int[10];
    }

    public static void fun2(int[] array) {
        array[0] = 10;
    }
